var ws, uid;
var pic;
document.addEventListener('plusready',function(){
	showWating();
	ws = plus.webview.currentWebview();
	uid = plus.storage.getItem('uid');
	//添加病例
	$('.bingli').click(function(){
		goNewPage('me-archives-home-add-case.html',{spage:ws.id});
	})
	console.log(JSON.stringify(apiRoot+"?m=home&c=member&a=archives&uid="+uid));
	$.ajax({
		type:"get",
		url:apiRoot+"?m=home&c=member&a=archives&uid="+uid, 
		dataType :'json',
		success : function(data){
			plus.nativeUI.closeWaiting();
			var str2 = '';
			$.each(data, function(key1,value1) { 
//				console.log(JSON.stringify(value1));
				str2 += '<div class="mui-table-view-cell mui-table-view case-list" bid="'+value1.aid+'">'+
							'<li>'+
								'<span>'+(value1.aidsname ? value1.aidsname : '')+'</span>'+
								'<span class="mui-h6 mui-pull-right">'+value1.ztime+'</span>'+
							'</li>'+
							'<li class="font-12 line-h-25">'+value1.history+'</li>'+
						'</div>';
			});
			$('.youbl').html(str2);
			$('.case-list').on('tap',function(){
				goNewPage('me-archives-home-add-case.html',{aid:$(this).attr('bid')})
			})
		},
		error :function(e){
			console.log(JSON.stringify(e));
			errortoast();
		}
	});
},false)

window.addEventListener('change',function(event){
	var bid = event.detail.bid;
	var aidsname = event.detail.aidsname;
	var ztime = event.detail.ztime;
	var bing = event.detail.bing;
	console.log(bid+"," +aidsname+', '+ztime+', '+bing);
	var list = '<div class="mui-table-view-cell mui-table-view case-list" bid="'+bid+'">'+
					'<li>'+
						'<span>'+aidsname+'</span>'+
						'<span class="mui-h6 mui-pull-right">'+ztime+'</span>'+
					'</li>'+
					'<li class="font-12 line-h-25">'+bing+'</li>'+
				'</div>';
	$('.youbl').prepend(list);
	$('.case-list').on('click',function(){
		goNewPage('me-archives-home-add-case.html',{aid:$(this).attr('bid')})
	})
})
//是否让家庭成员查看我的档案
function changeline(line){
	console.log(line); 
	$.ajax({
		type:"get",
		url:apiRoot+"?m=home&c=member&a=isfamily",
		data :{
			uid :uid,
			isfamily :line
		},
		dataType :'json',
		success :function(data){
			console.log(JSON.stringify(data));
			plus.nativeUI.closeWaiting();
			if(data > 0){
				if(line == 0){
					toast('关闭成功');
				}else{
					toast('开启成功'); 
				}
			}else{
				toast('修改失败');
			}
		},
		error :function(e){
			console.log(JSON.stringify(e));
			errortoast();
		}
	});
}
